package com.jlnx.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jlnx.dao.EnterpriseDaoImpl;
import com.jlnx.pojo.Enterprise;


@WebServlet("/CheckNameController")
public class CheckNameController extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		//获取请求信息
		response.setContentType("application/json;charset=UTF-8;text/html");
				String entNo = request.getParameter("account");
				System.out.println(entNo);				
				EnterpriseDaoImpl dao = new EnterpriseDaoImpl();
				
				//校验
				if(dao.checkNameIsExist(entNo) < 0) {
					//没找到，正常注册，200
					JSONObject jsonObject = new JSONObject();
					jsonObject.put("code", 200);
				    System.out.println(jsonObject);
			        response.getWriter().println(jsonObject);
				}else {
					//找到了，500
					JSONObject jsonObject = new JSONObject();
					jsonObject.put("code", 500);
				    System.out.println(jsonObject);
			        response.getWriter().println(jsonObject);
				}
	}

}
